package com.piggy.logi.sys.controller;

import com.piggy.common.core.domain.R;
import com.piggy.common.core.web.controller.BaseController;
import com.piggy.common.core.web.page.TableDataInfo;
import com.piggy.common.log.annotation.Log;
import com.piggy.common.log.annotation.LogiLog;
import com.piggy.common.log.enums.BusinessType;
import com.piggy.logi.sys.bo.LogiDrayageExtEditBo;
import com.piggy.logi.sys.bo.LogiDrayageQueryBo;
import com.piggy.logi.sys.enums.DrayageStatusEnum;
import com.piggy.logi.sys.service.ILogiDrayageService;
import com.piggy.logi.sys.vo.LogiDrayageExtVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * 短驳车次信息Controller
 *
 * @author piggy
 * @date 2023-09-18
 */
@Api(value = "短驳车次信息控制器", tags = {"短驳车次信息管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/sys/drayage")
public class LogiDrayageController extends BaseController {

    private final ILogiDrayageService iLogiDrayageService;

    /**
     * 查询短驳车次信息列表
     */
    @ApiOperation("查询短驳车次信息列表")
    //@SaCheckPermission("sys:drayage:list")
    @PostMapping("/list")
    public TableDataInfo<LogiDrayageExtVo> list(@Validated @RequestBody LogiDrayageQueryBo bo) {
        return iLogiDrayageService.queryPageList(bo);
    }

    /**
     * 获取短驳车次信息详细信息
     */
    @ApiOperation("获取短驳车次信息详细信息")
    //@SaCheckPermission("sys:drayage:query")
    @GetMapping("/{drayageId}")
    public R<LogiDrayageExtVo> getInfo(@NotNull(message = "主键不能为空")
                                    @PathVariable("drayageId") Long drayageId) {
        return R.ok(iLogiDrayageService.queryById(drayageId));
    }

    /**
     * 新增短驳车次信息
     */
    @ApiOperation("新增短驳车次信息")
    //@SaCheckPermission("sys:drayage:add")
    @LogiLog(title = "短驳车次信息", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<LogiDrayageExtVo> add(@Validated @RequestBody LogiDrayageExtEditBo bo) {
        return R.ok(iLogiDrayageService.insertByAddBo(bo));
    }

    /**
     * 新增短驳车次信息
     */
    @ApiOperation("短驳接收")
    //@SaCheckPermission("sys:drayage:add")
    @LogiLog(title = "短驳接收", businessType = BusinessType.INSERT)
    @PostMapping("/recv/{drayageNo}")
    public R<LogiDrayageExtVo> receive(@PathVariable("drayageNo") String drayageNo) {
        return R.ok(iLogiDrayageService.updateStatus(drayageNo, DrayageStatusEnum.RECEIVED.getCode()));
    }

    /**
     * 新增短驳车次信息
     */
    @ApiOperation("短驳取消接收")
    //@SaCheckPermission("sys:drayage:add")
    @LogiLog(title = "短驳取消接收", businessType = BusinessType.INSERT)
    @PostMapping("/cancelRecv/{drayageNo}")
    public R<LogiDrayageExtVo> cancelRecv(@PathVariable("drayageNo") String drayageNo) {
        return R.ok(iLogiDrayageService.updateStatus(drayageNo, DrayageStatusEnum.DEPARTURE.getCode()));
    }

    /**
     * 新增短驳车次信息
     */
    @ApiOperation("短驳取消发车")
    //@SaCheckPermission("sys:drayage:add")
    @LogiLog(title = "短驳取消发车", businessType = BusinessType.INSERT)
    @PostMapping("/cancelDeparture/{drayageNo}")
    public R<LogiDrayageExtVo> cancelDeparture(@PathVariable("drayageNo") String drayageNo) {
        return R.ok(iLogiDrayageService.updateStatus(drayageNo, DrayageStatusEnum.CANCEL.getCode()));
    }

}
